/**
 * 布局样式组件库
 * 统一页面布局相关的样式规范
 */

// 导入变量
@use '../variables.scss' as *;

// ==================== 页面容器样式 ====================
.page {
  &-container {
    min-height: 100vh;
    background: $content-bg;
    padding: $content-padding;
  }

  &-header {
    background: #fff;
    padding: $spacing-lg;
    margin-bottom: $spacing-lg;
    border-radius: $border-radius-lg;
    box-shadow: $shadow;
    display: flex;
    justify-content: space-between;
    align-items: center;

    &__title {
      font-size: $font-size-extra-large;
      font-weight: $font-weight-bold;
      color: $text-color;
      margin: 0;
    }

    &__subtitle {
      font-size: $font-size-base;
      color: $text-color-secondary;
      margin: $spacing-xs 0 0 0;
    }

    &__actions {
      display: flex;
      gap: $spacing-sm;
      align-items: center;
    }

    &--breadcrumb {
      .page-header__title {
        margin-bottom: $spacing-sm;
      }
    }
  }

  &-content {
    background: #fff;
    border-radius: $border-radius-lg;
    box-shadow: $shadow;
    overflow: hidden;
  }

  &-footer {
    margin-top: $spacing-lg;
    padding: $spacing-lg;
    text-align: center;
    color: $text-color-secondary;
    font-size: $font-size-small;
  }
}

// ==================== 网格布局样式 ====================
.grid {
  display: grid;
  gap: $spacing-lg;

  &--cols-1 { grid-template-columns: 1fr; }
  &--cols-2 { grid-template-columns: repeat(2, 1fr); }
  &--cols-3 { grid-template-columns: repeat(3, 1fr); }
  &--cols-4 { grid-template-columns: repeat(4, 1fr); }
  &--cols-5 { grid-template-columns: repeat(5, 1fr); }
  &--cols-6 { grid-template-columns: repeat(6, 1fr); }

  &--auto {
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  }

  &--gap-sm { gap: $spacing-sm; }
  &--gap-md { gap: $spacing-md; }
  &--gap-lg { gap: $spacing-lg; }
  &--gap-xl { gap: $spacing-xl; }

  &__item {
    &--span-2 { grid-column: span 2; }
    &--span-3 { grid-column: span 3; }
    &--span-4 { grid-column: span 4; }
    &--span-5 { grid-column: span 5; }
    &--span-6 { grid-column: span 6; }
  }
}

// ==================== 弹性布局样式 ====================
.flex {
  display: flex;

  &--row { flex-direction: row; }
  &--column { flex-direction: column; }
  &--row-reverse { flex-direction: row-reverse; }
  &--column-reverse { flex-direction: column-reverse; }

  &--wrap { flex-wrap: wrap; }
  &--nowrap { flex-wrap: nowrap; }
  &--wrap-reverse { flex-wrap: wrap-reverse; }

  &--justify-start { justify-content: flex-start; }
  &--justify-end { justify-content: flex-end; }
  &--justify-center { justify-content: center; }
  &--justify-between { justify-content: space-between; }
  &--justify-around { justify-content: space-around; }
  &--justify-evenly { justify-content: space-evenly; }

  &--align-start { align-items: flex-start; }
  &--align-end { align-items: flex-end; }
  &--align-center { align-items: center; }
  &--align-baseline { align-items: baseline; }
  &--align-stretch { align-items: stretch; }

  &--content-start { align-content: flex-start; }
  &--content-end { align-content: flex-end; }
  &--content-center { align-content: center; }
  &--content-between { align-content: space-between; }
  &--content-around { align-content: space-around; }
  &--content-stretch { align-content: stretch; }

  &--grow { flex-grow: 1; }
  &--shrink { flex-shrink: 1; }
  &--no-grow { flex-grow: 0; }
  &--no-shrink { flex-shrink: 0; }

  &--1 { flex: 1; }
  &--2 { flex: 2; }
  &--3 { flex: 3; }
  &--4 { flex: 4; }
  &--5 { flex: 5; }
  &--6 { flex: 6; }
}

// ==================== 间距样式 ====================
.spacing {
  &--xs { padding: $spacing-xs; }
  &--sm { padding: $spacing-sm; }
  &--md { padding: $spacing-md; }
  &--lg { padding: $spacing-lg; }
  &--xl { padding: $spacing-xl; }
  &--xxl { padding: $spacing-xxl; }

  &--t-xs { padding-top: $spacing-xs; }
  &--t-sm { padding-top: $spacing-sm; }
  &--t-md { padding-top: $spacing-md; }
  &--t-lg { padding-top: $spacing-lg; }
  &--t-xl { padding-top: $spacing-xl; }
  &--t-xxl { padding-top: $spacing-xxl; }

  &--b-xs { padding-bottom: $spacing-xs; }
  &--b-sm { padding-bottom: $spacing-sm; }
  &--b-md { padding-bottom: $spacing-md; }
  &--b-lg { padding-bottom: $spacing-lg; }
  &--b-xl { padding-bottom: $spacing-xl; }
  &--b-xxl { padding-bottom: $spacing-xxl; }

  &--l-xs { padding-left: $spacing-xs; }
  &--l-sm { padding-left: $spacing-sm; }
  &--l-md { padding-left: $spacing-md; }
  &--l-lg { padding-left: $spacing-lg; }
  &--l-xl { padding-left: $spacing-xl; }
  &--l-xxl { padding-left: $spacing-xxl; }

  &--r-xs { padding-right: $spacing-xs; }
  &--r-sm { padding-right: $spacing-sm; }
  &--r-md { padding-right: $spacing-md; }
  &--r-lg { padding-right: $spacing-lg; }
  &--r-xl { padding-right: $spacing-xl; }
  &--r-xxl { padding-right: $spacing-xxl; }

  &--x-xs { padding-left: $spacing-xs; padding-right: $spacing-xs; }
  &--x-sm { padding-left: $spacing-sm; padding-right: $spacing-sm; }
  &--x-md { padding-left: $spacing-md; padding-right: $spacing-md; }
  &--x-lg { padding-left: $spacing-lg; padding-right: $spacing-lg; }
  &--x-xl { padding-left: $spacing-xl; padding-right: $spacing-xl; }
  &--x-xxl { padding-left: $spacing-xxl; padding-right: $spacing-xxl; }

  &--y-xs { padding-top: $spacing-xs; padding-bottom: $spacing-xs; }
  &--y-sm { padding-top: $spacing-sm; padding-bottom: $spacing-sm; }
  &--y-md { padding-top: $spacing-md; padding-bottom: $spacing-md; }
  &--y-lg { padding-top: $spacing-lg; padding-bottom: $spacing-lg; }
  &--y-xl { padding-top: $spacing-xl; padding-bottom: $spacing-xl; }
  &--y-xxl { padding-top: $spacing-xxl; padding-bottom: $spacing-xxl; }
}

// ==================== 边距样式 ====================
.margin {
  &--xs { margin: $spacing-xs; }
  &--sm { margin: $spacing-sm; }
  &--md { margin: $spacing-md; }
  &--lg { margin: $spacing-lg; }
  &--xl { margin: $spacing-xl; }
  &--xxl { margin: $spacing-xxl; }

  &--t-xs { margin-top: $spacing-xs; }
  &--t-sm { margin-top: $spacing-sm; }
  &--t-md { margin-top: $spacing-md; }
  &--t-lg { margin-top: $spacing-lg; }
  &--t-xl { margin-top: $spacing-xl; }
  &--t-xxl { margin-top: $spacing-xxl; }

  &--b-xs { margin-bottom: $spacing-xs; }
  &--b-sm { margin-bottom: $spacing-sm; }
  &--b-md { margin-bottom: $spacing-md; }
  &--b-lg { margin-bottom: $spacing-lg; }
  &--b-xl { margin-bottom: $spacing-xl; }
  &--b-xxl { margin-bottom: $spacing-xxl; }

  &--l-xs { margin-left: $spacing-xs; }
  &--l-sm { margin-left: $spacing-sm; }
  &--l-md { margin-left: $spacing-md; }
  &--l-lg { margin-left: $spacing-lg; }
  &--l-xl { margin-left: $spacing-xl; }
  &--l-xxl { margin-left: $spacing-xxl; }

  &--r-xs { margin-right: $spacing-xs; }
  &--r-sm { margin-right: $spacing-sm; }
  &--r-md { margin-right: $spacing-md; }
  &--r-lg { margin-right: $spacing-lg; }
  &--r-xl { margin-right: $spacing-xl; }
  &--r-xxl { margin-right: $spacing-xxl; }

  &--x-xs { margin-left: $spacing-xs; margin-right: $spacing-xs; }
  &--x-sm { margin-left: $spacing-sm; margin-right: $spacing-sm; }
  &--x-md { margin-left: $spacing-md; margin-right: $spacing-md; }
  &--x-lg { margin-left: $spacing-lg; margin-right: $spacing-lg; }
  &--x-xl { margin-left: $spacing-xl; margin-right: $spacing-xl; }
  &--x-xxl { margin-left: $spacing-xxl; margin-right: $spacing-xxl; }

  &--y-xs { margin-top: $spacing-xs; margin-bottom: $spacing-xs; }
  &--y-sm { margin-top: $spacing-sm; margin-bottom: $spacing-sm; }
  &--y-md { margin-top: $spacing-md; margin-bottom: $spacing-md; }
  &--y-lg { margin-top: $spacing-lg; margin-bottom: $spacing-lg; }
  &--y-xl { margin-top: $spacing-xl; margin-bottom: $spacing-xl; }
  &--y-xxl { margin-top: $spacing-xxl; margin-bottom: $spacing-xxl; }

  &--auto { margin: auto; }
  &--x-auto { margin-left: auto; margin-right: auto; }
  &--y-auto { margin-top: auto; margin-bottom: auto; }
}

// ==================== 定位样式 ====================
.position {
  &--relative { position: relative; }
  &--absolute { position: absolute; }
  &--fixed { position: fixed; }
  &--sticky { position: sticky; }
  &--static { position: static; }

  &--top-0 { top: 0; }
  &--right-0 { right: 0; }
  &--bottom-0 { bottom: 0; }
  &--left-0 { left: 0; }

  &--top-50 { top: 50%; }
  &--left-50 { left: 50%; }
  &--top-50-left-50 { top: 50%; left: 50%; }

  &--z-0 { z-index: 0; }
  &--z-10 { z-index: 10; }
  &--z-20 { z-index: 20; }
  &--z-30 { z-index: 30; }
  &--z-40 { z-index: 40; }
  &--z-50 { z-index: 50; }
}

// ==================== 尺寸样式 ====================
.size {
  &--w-full { width: 100%; }
  &--w-auto { width: auto; }
  &--w-1\/2 { width: 50%; }
  &--w-1\/3 { width: 33.333333%; }
  &--w-2\/3 { width: 66.666667%; }
  &--w-1\/4 { width: 25%; }
  &--w-3\/4 { width: 75%; }

  &--h-full { height: 100%; }
  &--h-auto { height: auto; }
  &--h-screen { height: 100vh; }

  &--min-w-0 { min-width: 0; }
  &--min-h-0 { min-height: 0; }

  &--max-w-full { max-width: 100%; }
  &--max-h-full { max-height: 100%; }
}

// ==================== 显示样式 ====================
.display {
  &--block { display: block; }
  &--inline { display: inline; }
  &--inline-block { display: inline-block; }
  &--flex { display: flex; }
  &--grid { display: grid; }
  &--none { display: none; }
  &--table { display: table; }
  &--table-cell { display: table-cell; }
  &--table-row { display: table-row; }
}

// ==================== 溢出样式 ====================
.overflow {
  &--visible { overflow: visible; }
  &--hidden { overflow: hidden; }
  &--scroll { overflow: scroll; }
  &--auto { overflow: auto; }

  &--x-hidden { overflow-x: hidden; }
  &--x-scroll { overflow-x: scroll; }
  &--x-auto { overflow-x: auto; }

  &--y-hidden { overflow-y: hidden; }
  &--y-scroll { overflow-y: scroll; }
  &--y-auto { overflow-y: auto; }
}

// ==================== 响应式布局样式 ====================
@media (max-width: $breakpoint-sm) {
  .grid {
    &--cols-2,
    &--cols-3,
    &--cols-4,
    &--cols-5,
    &--cols-6 {
      grid-template-columns: 1fr;
    }
  }

  .flex {
    &--sm-column { flex-direction: column; }
    &--sm-wrap { flex-wrap: wrap; }
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: $spacing-md;

    &__actions {
      width: 100%;
      justify-content: flex-start;
    }
  }
}

@media (min-width: $breakpoint-sm) and (max-width: $breakpoint-md) {
  .grid {
    &--cols-3,
    &--cols-4,
    &--cols-5,
    &--cols-6 {
      grid-template-columns: repeat(2, 1fr);
    }
  }
}

@media (min-width: $breakpoint-md) and (max-width: $breakpoint-lg) {
  .grid {
    &--cols-4,
    &--cols-5,
    &--cols-6 {
      grid-template-columns: repeat(3, 1fr);
    }
  }
}

// ==================== 特殊布局样式 ====================
.container {
  max-width: $container-max-width;
  margin: 0 auto;
  padding: 0 $container-padding;

  &--fluid {
    max-width: none;
    padding: 0 $spacing-lg;
  }

  &--sm {
    max-width: 640px;
  }

  &--md {
    max-width: 768px;
  }

  &--lg {
    max-width: 1024px;
  }

  &--xl {
    max-width: 1280px;
  }
}

.section {
  padding: $spacing-xxl 0;

  &--sm {
    padding: $spacing-lg 0;
  }

  &--lg {
    padding: $spacing-xxl * 2 0;
  }

  &--no-padding {
    padding: 0;
  }
}

.aspect-ratio {
  position: relative;
  width: 100%;

  &--1-1 {
    aspect-ratio: 1 / 1;
  }

  &--16-9 {
    aspect-ratio: 16 / 9;
  }

  &--4-3 {
    aspect-ratio: 4 / 3;
  }

  &--3-2 {
    aspect-ratio: 3 / 2;
  }

  &__content {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}
